package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 拜访级别枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
public enum VisitLevelEnum {

    /**
     * 拜访级别 1:一般 2：重要
     */

    /**
     * 1:一般
     */
    COMMONLY(1, "一般"),

    /**
     * 2: 重要
     */
    IMPORTANT(2, "重要");

    VisitLevelEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static List<DropdownItem> toDropdownList() {
        List<DropdownItem> items = Arrays.stream(VisitLevelEnum.values()).sorted(Comparator.comparingInt(VisitLevelEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
        items.add(0 , new DropdownItem(0, MemberStringEnum.CHOOSE.getName()));
        return items;
    }

    public static List<DropdownItem> toEditableDropdownList() {
        return Arrays.stream(VisitLevelEnum.values()).sorted(Comparator.comparingInt(VisitLevelEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(VisitLevelEnum.class, code);
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 发票名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(VisitLevelEnum.class, code);
    }
}
